package com.lvmama.controller.dw;

import com.github.pagehelper.PageInfo;
import com.lvmama.pojo.dto.dw.RecommendAnalysisQuery;
import com.lvmama.pojo.entity.dw.recommend.OverView;
import com.lvmama.pojo.entity.dw.recommend.RecommendAnalysis;
import com.lvmama.pojo.entity.dw.recommend.Trend;
import com.lvmama.service.dw.RecommendAnalysisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @param
 * @Title:
 * @Author:wangpeng
 * @Description: TODO(这里用一句话描述这个方法的作用)
 * @return
 * @throws
 */
@Slf4j
@RestController
@RequestMapping(value = "/recommend")
public class RecommendController {

	@Autowired
	RecommendAnalysisService service;

	/**
	 * 根据条件导出csv的数据
	 * @param raDTO
	 * @return
	 * @throws
	 */
	@PostMapping(value = "/exportList")
	public List<RecommendAnalysis> exportList(@RequestBody RecommendAnalysisQuery raDTO){
		log.info("start exportList");
		List<RecommendAnalysis> result = null;
		try {
			result = service.exportList(raDTO);
		}catch (Exception e){
			log.error("exportList error:",e.getMessage(),e);
		}
		return result;
	}

	/**
	 * 业务：数据概览
	 * 根据条件查询 ->数据概览的数据
	 * @param raDTO
	 * @return OverView
	 */
	@PostMapping(value = "/overview")
	public OverView overview(@RequestBody RecommendAnalysisQuery raDTO){
		log.info("start service-controller overview");
		OverView overView = null;
		try {
			overView = service.overview(raDTO);
			log.info("end service-controller overview");
		}catch (Exception e){
			log.error("service-controller overview error:",e.getMessage(),e);
		}
		return overView;
	}

	/**
	 * 业务：数据趋势
	 * 根据条件查询 ->数据按照日期进行分组统计,得到每一日的点击率,转换率等数据
	 * @param raDTO
	 * @return Trend
	 */
	@PostMapping(value = "/trend")
	public Trend trend(@RequestBody RecommendAnalysisQuery raDTO) {
		log.info("start service-controller trend");
		Trend trend = null;
		try {
			trend = service.trend(raDTO);
		}catch (Exception e){
			log.error("service-controller trend error:",e.getMessage(),e);
		}
		return trend;
	}

	/**
	 * 业务：明细指标表格数据
	 * 根据条件查询 ->查询数据库中的原始数据明细
	 * @param raDTO
	 * @return PageInfo<RecommendAnalysis>
	 */
	@PostMapping(value = "/detail")
	public PageInfo<RecommendAnalysis> detailList(@RequestBody RecommendAnalysisQuery raDTO) {
		log.info("start service-controller trend");
		PageInfo<RecommendAnalysis> result = null;
		try {
			result = service.detailList(raDTO);
		}catch (Exception e){
			log.error("service-controller trend error:",e.getMessage(),e);
		}
		return result;
	}
}
